#!/bin/bash

echo "启动测试后端服务器..."

# 启动服务器1
echo "启动服务器1 (端口3001)..."
node test-servers/server1.js &
SERVER1_PID=$!

# 启动服务器2
echo "启动服务器2 (端口3002)..."
node test-servers/server2.js &
SERVER2_PID=$!

# 启动服务器3
echo "启动服务器3 (端口3003)..."
node test-servers/server3.js &
SERVER3_PID=$!

echo "所有测试服务器已启动:"
echo "- 服务器1: http://localhost:3001 (PID: $SERVER1_PID)"
echo "- 服务器2: http://localhost:3002 (PID: $SERVER2_PID)" 
echo "- 服务器3: http://localhost:3003 (PID: $SERVER3_PID)"
echo ""
echo "测试端点:"
echo "  GET /health - 健康检查"
echo "  GET / - 主页信息"
echo "  GET /api/users - 用户列表"
echo "  GET /api/status - 服务器状态"
echo "  GET /api/slow - 模拟慢接口"
echo ""
echo "按 Ctrl+C 停止所有服务器..."

# 创建信号处理程序
cleanup() {
    echo "正在停止所有服务器..."
    kill $SERVER1_PID $SERVER2_PID $SERVER3_PID 2>/dev/null
    wait
    echo "所有服务器已停止"
    exit 0
}

trap cleanup SIGINT SIGTERM

# 保持脚本运行
wait